#include <QTimer>
#include "JZLogManager.h"

//JZLogManager
JZLogManager *JZLogManager::instance()
{
    static JZLogManager inst;
    return &inst;
}

JZLogManager::JZLogManager()
{
    qRegisterMetaType<JZLogObjectPtr>("LogObjectPtr"); 
    m_timer = new QTimer(this);
}

JZLogManager::~JZLogManager()
{
}

void JZLogManager::init()
{

}

void JZLogManager::onTimeOut()
{

}

void JZLogManager::log(int module, int type, const QString &format, ...)
{    
    va_list var;
    va_start(var, format);
    QString buffer = QString::vasprintf(qUtf8Printable(format), var);
    va_end(var);

    //JZLogObjectPtr
    JZLogObjectPtr obj = JZLogObjectPtr(new JZLogObject());
    obj->level = type;
    obj->time = QDateTime::currentMSecsSinceEpoch();    
    obj->message = buffer;
    emit sigLog(obj);
}